var express = require('express');
var router = express.Router();
var http=require("http");

/* GET home page. */
//express跨域 百度的
router.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
//渲染页面
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
//请求数据
router.get('/lunbo',function(req,res,next){
  http.get('http://m.maizuo.com/v4/api/billboard/home?__t=1494913271816',function(ress){
    var str='';
    ress.on("data",function(chunk){
      str+=chunk;
    });
    ress.on('end',function(){
      res.send(str);
    });
    ress.on("error",function(err){
      console.log('err');
    })
  })
})
module.exports = router;
